package spells;
/*
 * basic healing spell
 */

import main.Creature;
import main.Grid;
import main.RandNum;

/**
 * A spell that heals the caster for some damage and temporarily raises the caster's maximum health for a duration
 */

public class Regrowth extends Spell {
   
    public Regrowth(){
        hasTarget = false;
        element = "Earth";
        name="Regrowth";
        description="A spell that temporarily raises the casters maximum health.\nPrimary stats:Intelligence\nRange=Self";
        castTime = 1;
        range=1;
    }
   
    public Regrowth(Creature caster)
    {
        this.caster=caster;
        hasTarget = false;
        element = "Regrowth";
        description="A spell that temporarily raises the casters maximum health.\nPrimary stats:Intelligence\nRange=Self";
        name="Heal";
        castTime = 1;
        range=1;
    }
   
    public void setCaster(Creature c){
        caster=c;
        cManaChange=caster.level*-2;
    }//end method
   
    public String applySpell(Grid g){
        cManaChange = caster.level * -2;
        cMaxHealthChange = caster.level *4;
        if(target!=null || !hasTarget){
            double distance;
            if(hasTarget)
                distance=g.getDToEnemy(target);
            else
                distance=0;
            if(caster.curMana+cManaChange>=0 && distance<=range){
                cHealthChange = (3*RandNum.randNum(1,3) + caster.intelligence);
                //do effect to target if there is a target
                if(hasTarget){
                    target.curHealth+=healthChange;
                    target.strength+=strChange;
                    target.stamina+=stamChange;
                    target.intelligence+=intChange;
                    target.spirit+=spChange;
                    target.curMana+=manaChange;
                    if(target.curHealth<0)
                        target.curHealth=0;
                    if(target.curHealth>target.maxHealth)
                        target.curHealth=target.maxHealth;
                    if(target.curMana<0)
                        target.curMana=0;
                    if(target.curMana>target.maxMana)
                        target.curMana=target.maxMana;
                }//end if
               
                //do effect to caster
                caster.curHealth+=cHealthChange;
                caster.strength+=cStrChange;
                caster.stamina+=cStamChange;
                caster.intelligence+=cIntChange;
                caster.spirit+=cSpChange;
                caster.curMana+=cManaChange;
                caster.maxHealth+=cMaxHealthChange;
                if(caster.curHealth<0)
                    caster.curHealth=0;
                if(caster.curHealth>caster.maxHealth)
                    caster.curHealth=caster.maxHealth;
                if(caster.curMana<0)
                    caster.curMana=0;
                if(caster.curMana>caster.maxMana)
                    caster.curMana=caster.maxMana;
               
                //determines what spell message to say
                if(hasTarget){
                    return caster.name+" has cast "+name+" at "+target.name+" dealing "+healthChange+" damage";
                }
                else{
                    StatChange moreHP = new StatChange(5);
                    moreHP.maxHealthChange = cMaxHealthChange;
                    moreHP.setName("Wild Growth");
                    caster.buffs.add(moreHP);
                    System.out.println("You gain Wild Growth, temporarily increasing your max health!");
                    return caster.name+" restores "+cHealthChange+" health";
                }
            }//end if
            //if you are out of range
            else if(distance>range){
                return "Out of range";
            }
            //if you are out of mana
            else{
                return "Not enough mana";
            }//end else
        }//end if
        return "";
    }//end method
}